package com.pig4cloud.pigx.pay.notice.impl;

import com.bblocks.enums.QueueBaseEnum;
import com.pig4cloud.pigx.pay.entity.PayTradeOrder;
import com.pig4cloud.pigx.pay.notice.PayResultNotice;
import com.rabbitmq.client.Channel;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cloud.client.loadbalancer.LoadBalancedRetryFactory;
import org.springframework.stereotype.Service;

/**
 * <p>Project: bblocks-pro - PayResultNoticeMq</p>
 * <p>描述：结果通知-mq通知</p>
 *
 * @Author Zhao [125043150@qq.com]
 * @Date 2023/10/9 23:44
 * @Version 1.0
 * @since 8
 */
@Slf4j
@RequiredArgsConstructor
/*@ConditionalOnClass({RabbitTemplate.class})//当ma启动的时候
@Service*/
public class PayResultNoticeMq implements PayResultNotice {

    private final RabbitTemplate rabbitTemplate;

    /**
     * 支付结果通知
     *
     * @param payOrder
     * @return 1=成功，
     */
    @Override
    public int noticePayResult(PayTradeOrder payOrder) {
        log.info("订单：{} mq推送支付结果:{}",payOrder.getPayNo(),payOrder.getStatus());

        rabbitTemplate.convertAndSend(QueueBaseEnum.QUEUE_PAY_RESULT.getExchange(),payOrder);
        return 1;
    }
}
